import {
	get,
	post
} from '@/api/request.js';

export function login(data) {
	return post('/wxuser', data, {}, false)
}
//注册企业
export function company_reg(data) {
	return post('/api/saveCompany/add', data, {}, true)
}
//产品类型
export function getProducts(data) {
	return post('/api/data', Object.assign({}, {
		"table_name": "ope_sku"
	}, data), {}, true)
}
//各级别单价
export function getLevelPrices(data) {
	return post('/api/data', Object.assign({}, {
		"model_code": "unitPrice"
	}, data), {}, true)
}
//获取用户信息
export function getUserInfo(data) {
	return post('/api/data', Object.assign({}, {
		"model_code": "userinfo"
	}, data), {}, true)
}
//获取税率
export function getTaxRate(data) {
	return post('/api/data', Object.assign({}, {
		"model_code": "tax"
	}, data), {}, true)
}
//添加/编辑地址
export function saveAddress(data) {
	let finalData = {
		"conds": [{
				"col": "province",
				"val": data.region[0]
			},
			{
				"col": "city",
				"val": data.region[1]
			},
			{
				"col": "district",
				"val": data.region[2]
			},
			{
				"col": "address",
				"val": data.address
			},
			{
				"col": "person",
				"val": data.person
			},
			{
				"col": "mobile",
				"val": data.mobile
			},
			{
				"col": "is_default",
				"val": data.isDefault
			},
			{
				"col": "id",
				"val": data.hasOwnProperty('id') ? data.id : ""
			}
		],
		"table_name": "sys_addr" //固定值
	};
	let url = data.hasOwnProperty('id') ? '/api/save/edit' : '/api/save/add';
	return post(url, finalData, {}, true)
}
export function delAddress(data) {
	let finalData = {
		"conds": [{
			"col": "id",
			"val": data.id
		}],
		"table_name": "sys_addr" //固定值
	};
	return post('/api/delete', finalData, {}, true)
}
export function setDefaultAddress(data) {
	let finalData = {
		"conds": [{
			"col": "id",
			"val": data.id
		}],
		"model_code": "defaultSysAddr", //固定值
	}
	return post('/api/fun', finalData, {}, true)
}
//我的地址
export function getAddress(data) {
	let finalData = {
		"conds": [{
			"col": "create_by", //固定值
			"opt": "=", //固定值
			"val": data.username //用户账号
		}],
		"table_name": "sys_addr", //固定值
	}
	return post('/api/data', finalData, {}, true)
}
export function getUserOrders(data) {
	let finalData = {
		"conds": [{
				"col": "oper.state_recycle",
				"val": data.status
			} // val 取值(""：全部  00：待审核，01：已驳回，02：已取消，03：已确认，04：已完结)
		],
		"model_code": "recycleList"
	};
	return post('/api/data', finalData, {}, true)
}
export function getOrderDetail(data) {
	let finalData = {
		"model_code": "recycleDetail",
		"conds": [{
			"col": "id",
			"opt": "=",
			"val": data.id
		}]
	}
	return post('/api/data', finalData, {}, true)
}
